package com.slt.developkitweb.config;

import com.slt.developkitweb.annotation.ShowAPI;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Author shalongteng
 * @Date 2023/9/4 14:23
 * @Description 单纯使用swagger3配置类，没找到如何配置扫描路径，
 * springfox 和 springdoc 都可以配置
 **/
@Configuration
@EnableOpenApi
public class SpringfoxSwagger3Config {
    @Bean(value = "swagger3")
    public Docket swagger3() {
        Docket docket = new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                //api 扫描路径，设置basePackage会将报下所有被@Api标记类的所有方法作为api
                .apis(RequestHandlerSelectors.withClassAnnotation(ShowAPI.class))
                //不去扫描请求路径，也就不会生成api文档
                .paths(PathSelectors.ant("/**" ))
                .build();
        return docket;
    }
    // 构建 api文档的详细信息函数,注意这里的注解引用的是哪个
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 页面标题
                .title("swagger3 API")
                // 创建人信息
                .contact(new Contact("slt", "", "1131790681@qq.com"))
                // 版本号
                .version("1.0")
                // 描述
                .description("swagger3 接口")
                .build();
    }
}

